package com.example.cloudsampleconsumer.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.cloudsampleconsumer.mapper.TestModelMapper;
import com.example.cloudsampleconsumer.model.TestModel;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class TestModelService extends ServiceImpl<TestModelMapper, TestModel> {
    @Autowired
    private CloudSampleProviderService cloudSampleProviderService;

    @GlobalTransactional
    public boolean saveTest() {
        TestModel insert = new TestModel();
        insert.setDateTime(LocalDateTime.now());
        insert.setValue("consumer");
        boolean save = save(insert);
        System.out.println("provider save " + save);
        insert.setValue(insert.getValue() + "-provider");
        int i = 9 / 0;
        boolean save1 = cloudSampleProviderService.save(insert);
        Object byId = cloudSampleProviderService.getById(insert.getId());
        System.out.println(JSON.toJSONString(byId));
        return true;
    }
}
